#include "StdAfx.h"
#include "AccountsMgr.h"
#include "CtpTraderSpi.h"

CAccountsMgr* CAccountsMgr::Instance()
{
	static CAccountsMgr s_accounts_mgr;
	return & s_accounts_mgr;
}

CAccountsMgr::CAccountsMgr()
{

}

CAccountsMgr::~CAccountsMgr(void)
{
}

void CAccountsMgr::AddAccount(const std::string& companay,
				const std::string& name,
				const std::string& pwd,
				const std::string& srv,
				int port)
{
	CAccountMonitor* pAM = new CAccountMonitor(CAccountMonitor::ACCOUNT_CTP, companay, name, pwd, srv, port);
	_accounts.push_back(pAM);
}

void CAccountsMgr::RemoveAccount(CAccountMonitor* am)
{
	for(std::vector<CAccountMonitor*>::iterator itr = _accounts.begin(); itr != _accounts.end();)
	{
		if(*itr == am)
		{
			delete am;
			itr = _accounts.erase(itr);
		}
		else
			++itr;
	}
}